<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>WebSocket</title>

    <script type="text/javascript">
        window.onload = function () {
            //页面加载完成后执行的函数
            console.log("ready");
            // 创建WebSocket连接.
            window.__webSocket = new WebSocket('ws://' + window.location.host + '/my');

            // 连接成功触发
            window.__webSocket.addEventListener('open', function (event) {
                window.__webSocket.send('Hello Server!');
            });

            // 监听消息
            window.__webSocket.addEventListener('message', function (event) {
                console.log('Message from server ', event.data);
            });
            console.log('success');
        };



    </script>

</head>
<body>

</body>
</html>